home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group93c.txt / 000123_icon-group-sender _Wed Dec 15 20:29:55 1993.msg < prev    next >
Internet Message Format  |  1994-02-02  |  2KB

  1. Received: by cheltenham.cs.arizona.edu; Thu, 16 Dec 1993 08:33:58 MST
  2. Date: Wed, 15 Dec 93 20:29:55 pst
  3. From: balexander@ccmail.com
  4. Message-Id: <9311157560.AA756016195@smtpgate.ccmail.com>
  5. To: icon-group@cs.arizona.edu
  6. Subject: Re[2]: Need help with (simple?) programming problem.
  7. Status: R
  8. Errors-To: icon-group-errors@cs.arizona.edu
  9.  
  10.  
  11. I first sent my hack at this problem only to Mr. Guilmette, but I decided to 
  12. post it to the 'group since the result turned out especially "cute".  I'm not 
  13. sure this terse solution is quite what he was looking for, but it is kind of 
  14. interesting (and shorter than Ken Walker's  :-)  a notable achievement since 
  15. Ken is a truly top-notch Icon programmer).  Another example of one of my 
  16. favorite Icon techniques:  recursive generation (or generative recursion?).
  17.  
  18.  
  19. procedure main()
  20.   every write(image(gen(["red ", "green ", "blue "])))
  21. end
  22.  
  23. procedure gen(strings, s, i)
  24.   /s := "" & i := 1
  25.   if i > *strings then return s
  26.   else every (t := ("" | !strings)) & (not find(t, "" ~== s)) do
  27.       suspend gen(strings, s || t, i + 1)
  28. end
  29.  
  30. _______________________________________________________________________________
  31.  
  32. > From Ronal F. Guilmette:
  33. >
  34. > Assume that I have three strings, i.e. "red ", "green ", and "blue ". Now
  35. > I want to create a generator which will successively yield each unique
  36. > string which contains no more than one instance of each of the original
  37. > strings.  Here are the string values which should be yielded by the various
  38. > invocations/resumptions of the generator:
  39. >   ""
  40. >   "red "
  41. >   "green "
  42. >   "blue "
  43. >   "red green "
  44. >   "red blue "
  45. >   "green red "
  46. >   "green blue "
  47. >   "blue red "
  48. >   "blue green "
  49. >   "red green blue "
  50. >   "red blue green "
  51. >   "green red blue "
  52. >   "green blue red "
  53. >   "blue red green "
  54. >   "blue green red "
  55.